<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - Lua 5.4.0-alpha - src/lutf8lib.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - lutf8lib.c</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">Lua 5.4.0-alpha</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">131</td>
            <td class="headerCovTableEntry">134</td>
            <td class="headerCovTableEntryHi">97.8 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2019-06-13 19:44:19</td>
            <td></td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : /*
<span class="lineNum">       2 </span>            : ** $Id: lutf8lib.c $
<span class="lineNum">       3 </span>            : ** Standard library for UTF-8 manipulation
<span class="lineNum">       4 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">       5 </span>            : */
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #define lutf8lib_c
<span class="lineNum">       8 </span>            : #define LUA_LIB
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : #include &quot;lprefix.h&quot;
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : #include &lt;assert.h&gt;
<span class="lineNum">      14 </span>            : #include &lt;limits.h&gt;
<span class="lineNum">      15 </span>            : #include &lt;stdlib.h&gt;
<span class="lineNum">      16 </span>            : #include &lt;string.h&gt;
<span class="lineNum">      17 </span>            : 
<span class="lineNum">      18 </span>            : #include &quot;lua.h&quot;
<span class="lineNum">      19 </span>            : 
<span class="lineNum">      20 </span>            : #include &quot;lauxlib.h&quot;
<span class="lineNum">      21 </span>            : #include &quot;lualib.h&quot;
<span class="lineNum">      22 </span>            : 
<span class="lineNum">      23 </span>            : 
<span class="lineNum">      24 </span>            : #define MAXUNICODE      0x10FFFFu
<span class="lineNum">      25 </span>            : 
<span class="lineNum">      26 </span>            : #define MAXUTF          0x7FFFFFFFu
<span class="lineNum">      27 </span>            : 
<span class="lineNum">      28 </span>            : /*
<span class="lineNum">      29 </span>            : ** Integer type for decoded UTF-8 values; MAXUTF needs 31 bits.
<span class="lineNum">      30 </span>            : */
<span class="lineNum">      31 </span>            : #if (UINT_MAX &gt;&gt; 30) &gt;= 1
<span class="lineNum">      32 </span>            : typedef unsigned int utfint;
<span class="lineNum">      33 </span>            : #else
<span class="lineNum">      34 </span>            : typedef unsigned long utfint;
<span class="lineNum">      35 </span>            : #endif
<span class="lineNum">      36 </span>            : 
<span class="lineNum">      37 </span>            : 
<span class="lineNum">      38 </span>            : #define iscont(p)       ((*(p) &amp; 0xC0) == 0x80)
<span class="lineNum">      39 </span>            : 
<span class="lineNum">      40 </span>            : 
<span class="lineNum">      41 </span>            : /* from strlib */
<span class="lineNum">      42 </span>            : /* translate a relative string position: negative means back from end */
<span class="lineNum">      43 </span><span class="lineCov">         79 : static lua_Integer u_posrelat (lua_Integer pos, size_t len) {</span>
<span class="lineNum">      44 </span><span class="lineCov">         79 :   if (pos &gt;= 0) return pos;</span>
<span class="lineNum">      45 </span><span class="lineCov">         21 :   else if (0u - (size_t)pos &gt; len) return 0;</span>
<span class="lineNum">      46 </span><span class="lineCov">         20 :   else return (lua_Integer)len + pos + 1;</span>
<span class="lineNum">      47 </span>            : }
<span class="lineNum">      48 </span>            : 
<span class="lineNum">      49 </span>            : 
<span class="lineNum">      50 </span>            : /*
<span class="lineNum">      51 </span>            : ** Decode one UTF-8 sequence, returning NULL if byte sequence is
<span class="lineNum">      52 </span>            : ** invalid.  The array 'limits' stores the minimum value for each
<span class="lineNum">      53 </span>            : ** sequence length, to check for overlong representations. Its first
<span class="lineNum">      54 </span>            : ** entry forces an error for non-ascii bytes with no continuation
<span class="lineNum">      55 </span>            : ** bytes (count == 0).
<span class="lineNum">      56 </span>            : */
<span class="lineNum">      57 </span><span class="lineCov">         42 : static const char *utf8_decode (const char *s, utfint *val, int strict) {</span>
<span class="lineNum">      58 </span>            :   static const utfint limits[] =
<span class="lineNum">      59 </span>            :         {~(utfint)0, 0x80, 0x800, 0x10000u, 0x200000u, 0x4000000u};
<span class="lineNum">      60 </span><span class="lineCov">         42 :   unsigned int c = (unsigned char)s[0];</span>
<span class="lineNum">      61 </span><span class="lineCov">         42 :   utfint res = 0;  /* final result */</span>
<span class="lineNum">      62 </span><span class="lineCov">         42 :   if (c &lt; 0x80)  /* ascii? */</span>
<span class="lineNum">      63 </span><span class="lineCov">         34 :     res = c;</span>
<span class="lineNum">      64 </span>            :   else {
<span class="lineNum">      65 </span><span class="lineCov">          8 :     int count = 0;  /* to count number of continuation bytes */</span>
<span class="lineNum">      66 </span><span class="lineCov">         18 :     for (; c &amp; 0x40; c &lt;&lt;= 1) {  /* while it needs continuation bytes... */</span>
<span class="lineNum">      67 </span><span class="lineCov">         13 :       unsigned int cc = (unsigned char)s[++count];  /* read next byte */</span>
<span class="lineNum">      68 </span><span class="lineCov">         13 :       if ((cc &amp; 0xC0) != 0x80)  /* not a continuation byte? */</span>
<span class="lineNum">      69 </span><span class="lineCov">          3 :         return NULL;  /* invalid byte sequence */</span>
<span class="lineNum">      70 </span><span class="lineCov">         10 :       res = (res &lt;&lt; 6) | (cc &amp; 0x3F);  /* add lower 6 bits from cont. byte */</span>
<span class="lineNum">      71 </span>            :     }
<span class="lineNum">      72 </span><span class="lineCov">          5 :     res |= ((utfint)(c &amp; 0x7F) &lt;&lt; (count * 5));  /* add first byte */</span>
<span class="lineNum">      73 </span><span class="lineCov">          5 :     if (count &gt; 5 || res &gt; MAXUTF || res &lt; limits[count])</span>
<span class="lineNum">      74 </span><span class="lineNoCov">          0 :       return NULL;  /* invalid byte sequence */</span>
<span class="lineNum">      75 </span><span class="lineCov">          5 :     s += count;  /* skip continuation bytes read */</span>
<span class="lineNum">      76 </span>            :   }
<span class="lineNum">      77 </span><span class="lineCov">         39 :   if (strict) {</span>
<span class="lineNum">      78 </span>            :     /* check for invalid code points; too large or surrogates */
<span class="lineNum">      79 </span><span class="lineCov">         32 :     if (res &gt; MAXUNICODE || (0xD800u &lt;= res &amp;&amp; res &lt;= 0xDFFFu))</span>
<span class="lineNum">      80 </span><span class="lineNoCov">          0 :       return NULL;</span>
<span class="lineNum">      81 </span>            :   }
<span class="lineNum">      82 </span><span class="lineCov">         39 :   if (val) *val = res;</span>
<span class="lineNum">      83 </span><span class="lineCov">         39 :   return s + 1;  /* +1 to include first byte */</span>
<span class="lineNum">      84 </span>            : }
<span class="lineNum">      85 </span>            : 
<span class="lineNum">      86 </span>            : 
<span class="lineNum">      87 </span>            : /*
<span class="lineNum">      88 </span>            : ** utf8len(s [, i [, j [, lax]]]) --&gt; number of characters that
<span class="lineNum">      89 </span>            : ** start in the range [i,j], or nil + current position if 's' is not
<span class="lineNum">      90 </span>            : ** well formed in that interval
<span class="lineNum">      91 </span>            : */
<span class="lineNum">      92 </span><span class="lineCov">         12 : static int utflen (lua_State *L) {</span>
<span class="lineNum">      93 </span><span class="lineCov">         12 :   lua_Integer n = 0;  /* counter for the number of characters */</span>
<span class="lineNum">      94 </span>            :   size_t len;  /* string length in bytes */
<span class="lineNum">      95 </span><span class="lineCov">         12 :   const char *s = luaL_checklstring(L, 1, &amp;len);</span>
<span class="lineNum">      96 </span><span class="lineCov">         12 :   lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);</span>
<span class="lineNum">      97 </span><span class="lineCov">         12 :   lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len);</span>
<span class="lineNum">      98 </span><span class="lineCov">         12 :   int lax = lua_toboolean(L, 4);</span>
<span class="lineNum">      99 </span><span class="lineCov">         12 :   luaL_argcheck(L, 1 &lt;= posi &amp;&amp; --posi &lt;= (lua_Integer)len, 2,</span>
<span class="lineNum">     100 </span>            :                    &quot;initial position out of string&quot;);
<span class="lineNum">     101 </span><span class="lineCov">         11 :   luaL_argcheck(L, --posj &lt; (lua_Integer)len, 3,</span>
<span class="lineNum">     102 </span>            :                    &quot;final position out of string&quot;);
<span class="lineNum">     103 </span><span class="lineCov">         31 :   while (posi &lt;= posj) {</span>
<span class="lineNum">     104 </span><span class="lineCov">         21 :     const char *s1 = utf8_decode(s + posi, NULL, !lax);</span>
<span class="lineNum">     105 </span><span class="lineCov">         21 :     if (s1 == NULL) {  /* conversion error? */</span>
<span class="lineNum">     106 </span><span class="lineCov">          1 :       lua_pushnil(L);  /* return nil ... */</span>
<span class="lineNum">     107 </span><span class="lineCov">          1 :       lua_pushinteger(L, posi + 1);  /* ... and current position */</span>
<span class="lineNum">     108 </span><span class="lineCov">          1 :       return 2;</span>
<span class="lineNum">     109 </span>            :     }
<span class="lineNum">     110 </span><span class="lineCov">         20 :     posi = s1 - s;</span>
<span class="lineNum">     111 </span><span class="lineCov">         20 :     n++;</span>
<span class="lineNum">     112 </span>            :   }
<span class="lineNum">     113 </span><span class="lineCov">         10 :   lua_pushinteger(L, n);</span>
<span class="lineNum">     114 </span><span class="lineCov">         10 :   return 1;</span>
<span class="lineNum">     115 </span>            : }
<span class="lineNum">     116 </span>            : 
<span class="lineNum">     117 </span>            : 
<span class="lineNum">     118 </span>            : /*
<span class="lineNum">     119 </span>            : ** codepoint(s, [i, [j [, lax]]]) -&gt; returns codepoints for all
<span class="lineNum">     120 </span>            : ** characters that start in the range [i,j]
<span class="lineNum">     121 </span>            : */
<span class="lineNum">     122 </span><span class="lineCov">          9 : static int codepoint (lua_State *L) {</span>
<span class="lineNum">     123 </span>            :   size_t len;
<span class="lineNum">     124 </span><span class="lineCov">          9 :   const char *s = luaL_checklstring(L, 1, &amp;len);</span>
<span class="lineNum">     125 </span><span class="lineCov">          9 :   lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);</span>
<span class="lineNum">     126 </span><span class="lineCov">          9 :   lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len);</span>
<span class="lineNum">     127 </span><span class="lineCov">          9 :   int lax = lua_toboolean(L, 4);</span>
<span class="lineNum">     128 </span>            :   int n;
<span class="lineNum">     129 </span>            :   const char *se;
<span class="lineNum">     130 </span><span class="lineCov">          9 :   luaL_argcheck(L, posi &gt;= 1, 2, &quot;out of range&quot;);</span>
<span class="lineNum">     131 </span><span class="lineCov">          9 :   luaL_argcheck(L, pose &lt;= (lua_Integer)len, 3, &quot;out of range&quot;);</span>
<span class="lineNum">     132 </span><span class="lineCov">          7 :   if (posi &gt; pose) return 0;  /* empty interval; return no values */</span>
<span class="lineNum">     133 </span><span class="lineCov">          7 :   if (pose - posi &gt;= INT_MAX)  /* (lua_Integer -&gt; int) overflow? */</span>
<span class="lineNum">     134 </span><span class="lineNoCov">          0 :     return luaL_error(L, &quot;string slice too long&quot;);</span>
<span class="lineNum">     135 </span><span class="lineCov">          7 :   n = (int)(pose -  posi) + 1;  /* upper bound for number of returns */</span>
<span class="lineNum">     136 </span><span class="lineCov">          7 :   luaL_checkstack(L, n, &quot;string slice too long&quot;);</span>
<span class="lineNum">     137 </span><span class="lineCov">          7 :   n = 0;  /* count the number of returns */</span>
<span class="lineNum">     138 </span><span class="lineCov">          7 :   se = s + pose;  /* string end */</span>
<span class="lineNum">     139 </span><span class="lineCov">         16 :   for (s += posi - 1; s &lt; se;) {</span>
<span class="lineNum">     140 </span>            :     utfint code;
<span class="lineNum">     141 </span><span class="lineCov">         10 :     s = utf8_decode(s, &amp;code, !lax);</span>
<span class="lineNum">     142 </span><span class="lineCov">         10 :     if (s == NULL)</span>
<span class="lineNum">     143 </span><span class="lineCov">          1 :       return luaL_error(L, &quot;invalid UTF-8 code&quot;);</span>
<span class="lineNum">     144 </span><span class="lineCov">          9 :     lua_pushinteger(L, code);</span>
<span class="lineNum">     145 </span><span class="lineCov">          9 :     n++;</span>
<span class="lineNum">     146 </span>            :   }
<span class="lineNum">     147 </span><span class="lineCov">          6 :   return n;</span>
<span class="lineNum">     148 </span>            : }
<span class="lineNum">     149 </span>            : 
<span class="lineNum">     150 </span>            : 
<span class="lineNum">     151 </span><span class="lineCov">          8 : static void pushutfchar (lua_State *L, int arg) {</span>
<span class="lineNum">     152 </span><span class="lineCov">          8 :   lua_Unsigned code = (lua_Unsigned)luaL_checkinteger(L, arg);</span>
<span class="lineNum">     153 </span><span class="lineCov">          7 :   luaL_argcheck(L, code &lt;= MAXUTF, arg, &quot;value out of range&quot;);</span>
<span class="lineNum">     154 </span><span class="lineCov">          6 :   lua_pushfstring(L, &quot;%U&quot;, (long)code);</span>
<span class="lineNum">     155 </span><span class="lineCov">          6 : }</span>
<span class="lineNum">     156 </span>            : 
<span class="lineNum">     157 </span>            : 
<span class="lineNum">     158 </span>            : /*
<span class="lineNum">     159 </span>            : ** utfchar(n1, n2, ...)  -&gt; char(n1)..char(n2)...
<span class="lineNum">     160 </span>            : */
<span class="lineNum">     161 </span><span class="lineCov">          5 : static int utfchar (lua_State *L) {</span>
<span class="lineNum">     162 </span><span class="lineCov">          5 :   int n = lua_gettop(L);  /* number of arguments */</span>
<span class="lineNum">     163 </span><span class="lineCov">          5 :   if (n == 1)  /* optimize common case of single char */</span>
<span class="lineNum">     164 </span><span class="lineCov">          1 :     pushutfchar(L, 1);</span>
<span class="lineNum">     165 </span>            :   else {
<span class="lineNum">     166 </span>            :     int i;
<span class="lineNum">     167 </span>            :     luaL_Buffer b;
<span class="lineNum">     168 </span><span class="lineCov">          4 :     luaL_buffinit(L, &amp;b);</span>
<span class="lineNum">     169 </span><span class="lineCov">          9 :     for (i = 1; i &lt;= n; i++) {</span>
<span class="lineNum">     170 </span><span class="lineCov">          7 :       pushutfchar(L, i);</span>
<span class="lineNum">     171 </span><span class="lineCov">          5 :       luaL_addvalue(&amp;b);</span>
<span class="lineNum">     172 </span>            :     }
<span class="lineNum">     173 </span><span class="lineCov">          2 :     luaL_pushresult(&amp;b);</span>
<span class="lineNum">     174 </span>            :   }
<span class="lineNum">     175 </span><span class="lineCov">          3 :   return 1;</span>
<span class="lineNum">     176 </span>            : }
<span class="lineNum">     177 </span>            : 
<span class="lineNum">     178 </span>            : 
<span class="lineNum">     179 </span>            : /*
<span class="lineNum">     180 </span>            : ** offset(s, n, [i])  -&gt; index where n-th character counting from
<span class="lineNum">     181 </span>            : **   position 'i' starts; 0 means character at 'i'.
<span class="lineNum">     182 </span>            : */
<span class="lineNum">     183 </span><span class="lineCov">         37 : static int byteoffset (lua_State *L) {</span>
<span class="lineNum">     184 </span>            :   size_t len;
<span class="lineNum">     185 </span><span class="lineCov">         37 :   const char *s = luaL_checklstring(L, 1, &amp;len);</span>
<span class="lineNum">     186 </span><span class="lineCov">         37 :   lua_Integer n  = luaL_checkinteger(L, 2);</span>
<span class="lineNum">     187 </span><span class="lineCov">         37 :   lua_Integer posi = (n &gt;= 0) ? 1 : len + 1;</span>
<span class="lineNum">     188 </span><span class="lineCov">         37 :   posi = u_posrelat(luaL_optinteger(L, 3, posi), len);</span>
<span class="lineNum">     189 </span><span class="lineCov">         37 :   luaL_argcheck(L, 1 &lt;= posi &amp;&amp; --posi &lt;= (lua_Integer)len, 3,</span>
<span class="lineNum">     190 </span>            :                    &quot;position out of range&quot;);
<span class="lineNum">     191 </span><span class="lineCov">         36 :   if (n == 0) {</span>
<span class="lineNum">     192 </span>            :     /* find beginning of current byte sequence */
<span class="lineNum">     193 </span><span class="lineCov">          9 :     while (posi &gt; 0 &amp;&amp; iscont(s + posi)) posi--;</span>
<span class="lineNum">     194 </span>            :   }
<span class="lineNum">     195 </span>            :   else {
<span class="lineNum">     196 </span><span class="lineCov">         30 :     if (iscont(s + posi))</span>
<span class="lineNum">     197 </span><span class="lineCov">          1 :       return luaL_error(L, &quot;initial position is a continuation byte&quot;);</span>
<span class="lineNum">     198 </span><span class="lineCov">         29 :     if (n &lt; 0) {</span>
<span class="lineNum">     199 </span><span class="lineCov">         26 :        while (n &lt; 0 &amp;&amp; posi &gt; 0) {  /* move back */</span>
<span class="lineNum">     200 </span>            :          do {  /* find beginning of previous character */
<span class="lineNum">     201 </span><span class="lineCov">         27 :            posi--;</span>
<span class="lineNum">     202 </span><span class="lineCov">         27 :          } while (posi &gt; 0 &amp;&amp; iscont(s + posi));</span>
<span class="lineNum">     203 </span><span class="lineCov">         15 :          n++;</span>
<span class="lineNum">     204 </span>            :        }
<span class="lineNum">     205 </span>            :      }
<span class="lineNum">     206 </span>            :      else {
<span class="lineNum">     207 </span><span class="lineCov">         18 :        n--;  /* do not move for 1st character */</span>
<span class="lineNum">     208 </span><span class="lineCov">         38 :        while (n &gt; 0 &amp;&amp; posi &lt; (lua_Integer)len) {</span>
<span class="lineNum">     209 </span>            :          do {  /* find beginning of next character */
<span class="lineNum">     210 </span><span class="lineCov">         36 :            posi++;</span>
<span class="lineNum">     211 </span><span class="lineCov">         36 :          } while (iscont(s + posi));  /* (cannot pass final '\0') */</span>
<span class="lineNum">     212 </span><span class="lineCov">         20 :          n--;</span>
<span class="lineNum">     213 </span>            :        }
<span class="lineNum">     214 </span>            :      }
<span class="lineNum">     215 </span>            :   }
<span class="lineNum">     216 </span><span class="lineCov">         35 :   if (n == 0)  /* did it find given character? */</span>
<span class="lineNum">     217 </span><span class="lineCov">         26 :     lua_pushinteger(L, posi + 1);</span>
<span class="lineNum">     218 </span>            :   else  /* no such character */
<span class="lineNum">     219 </span><span class="lineCov">          9 :     lua_pushnil(L);</span>
<span class="lineNum">     220 </span><span class="lineCov">         35 :   return 1;</span>
<span class="lineNum">     221 </span>            : }
<span class="lineNum">     222 </span>            : 
<span class="lineNum">     223 </span>            : 
<span class="lineNum">     224 </span><span class="lineCov">         13 : static int iter_aux (lua_State *L, int strict) {</span>
<span class="lineNum">     225 </span>            :   size_t len;
<span class="lineNum">     226 </span><span class="lineCov">         13 :   const char *s = luaL_checklstring(L, 1, &amp;len);</span>
<span class="lineNum">     227 </span><span class="lineCov">         13 :   lua_Integer n = lua_tointeger(L, 2) - 1;</span>
<span class="lineNum">     228 </span><span class="lineCov">         13 :   if (n &lt; 0)  /* first iteration? */</span>
<span class="lineNum">     229 </span><span class="lineCov">          3 :     n = 0;  /* start from here */</span>
<span class="lineNum">     230 </span><span class="lineCov">         10 :   else if (n &lt; (lua_Integer)len) {</span>
<span class="lineNum">     231 </span><span class="lineCov">         10 :     n++;  /* skip current byte */</span>
<span class="lineNum">     232 </span><span class="lineCov">         12 :     while (iscont(s + n)) n++;  /* and its continuations */</span>
<span class="lineNum">     233 </span>            :   }
<span class="lineNum">     234 </span><span class="lineCov">         13 :   if (n &gt;= (lua_Integer)len)</span>
<span class="lineNum">     235 </span><span class="lineCov">          2 :     return 0;  /* no more codepoints */</span>
<span class="lineNum">     236 </span>            :   else {
<span class="lineNum">     237 </span>            :     utfint code;
<span class="lineNum">     238 </span><span class="lineCov">         11 :     const char *next = utf8_decode(s + n, &amp;code, strict);</span>
<span class="lineNum">     239 </span><span class="lineCov">         11 :     if (next == NULL)</span>
<span class="lineNum">     240 </span><span class="lineCov">          1 :       return luaL_error(L, &quot;invalid UTF-8 code&quot;);</span>
<span class="lineNum">     241 </span><span class="lineCov">         10 :     lua_pushinteger(L, n + 1);</span>
<span class="lineNum">     242 </span><span class="lineCov">         10 :     lua_pushinteger(L, code);</span>
<span class="lineNum">     243 </span><span class="lineCov">         10 :     return 2;</span>
<span class="lineNum">     244 </span>            :   }
<span class="lineNum">     245 </span>            : }
<span class="lineNum">     246 </span>            : 
<span class="lineNum">     247 </span>            : 
<span class="lineNum">     248 </span><span class="lineCov">          9 : static int iter_auxstrict (lua_State *L) {</span>
<span class="lineNum">     249 </span><span class="lineCov">          9 :   return iter_aux(L, 1);</span>
<span class="lineNum">     250 </span>            : }
<span class="lineNum">     251 </span>            : 
<span class="lineNum">     252 </span><span class="lineCov">          4 : static int iter_auxlax (lua_State *L) {</span>
<span class="lineNum">     253 </span><span class="lineCov">          4 :   return iter_aux(L, 0);</span>
<span class="lineNum">     254 </span>            : }
<span class="lineNum">     255 </span>            : 
<span class="lineNum">     256 </span>            : 
<span class="lineNum">     257 </span><span class="lineCov">          5 : static int iter_codes (lua_State *L) {</span>
<span class="lineNum">     258 </span><span class="lineCov">          5 :   int lax = lua_toboolean(L, 2);</span>
<span class="lineNum">     259 </span><span class="lineCov">          5 :   luaL_checkstring(L, 1);</span>
<span class="lineNum">     260 </span><span class="lineCov">          3 :   lua_pushcfunction(L, lax ? iter_auxlax : iter_auxstrict);</span>
<span class="lineNum">     261 </span><span class="lineCov">          3 :   lua_pushvalue(L, 1);</span>
<span class="lineNum">     262 </span><span class="lineCov">          3 :   lua_pushinteger(L, 0);</span>
<span class="lineNum">     263 </span><span class="lineCov">          3 :   return 3;</span>
<span class="lineNum">     264 </span>            : }
<span class="lineNum">     265 </span>            : 
<span class="lineNum">     266 </span>            : 
<span class="lineNum">     267 </span>            : /* pattern to match a single UTF-8 character */
<span class="lineNum">     268 </span>            : #define UTF8PATT        &quot;[\0-\x7F\xC2-\xFD][\x80-\xBF]*&quot;
<span class="lineNum">     269 </span>            : 
<span class="lineNum">     270 </span>            : 
<span class="lineNum">     271 </span>            : static const luaL_Reg funcs[] = {
<span class="lineNum">     272 </span>            :   {&quot;offset&quot;, byteoffset},
<span class="lineNum">     273 </span>            :   {&quot;codepoint&quot;, codepoint},
<span class="lineNum">     274 </span>            :   {&quot;char&quot;, utfchar},
<span class="lineNum">     275 </span>            :   {&quot;len&quot;, utflen},
<span class="lineNum">     276 </span>            :   {&quot;codes&quot;, iter_codes},
<span class="lineNum">     277 </span>            :   /* placeholders */
<span class="lineNum">     278 </span>            :   {&quot;charpattern&quot;, NULL},
<span class="lineNum">     279 </span>            :   {NULL, NULL}
<span class="lineNum">     280 </span>            : };
<span class="lineNum">     281 </span>            : 
<span class="lineNum">     282 </span>            : 
<span class="lineNum">     283 </span><span class="lineCov">         89 : LUAMOD_API int luaopen_utf8 (lua_State *L) {</span>
<span class="lineNum">     284 </span><span class="lineCov">         89 :   luaL_newlib(L, funcs);</span>
<span class="lineNum">     285 </span><span class="lineCov">         89 :   lua_pushlstring(L, UTF8PATT, sizeof(UTF8PATT)/sizeof(char) - 1);</span>
<span class="lineNum">     286 </span><span class="lineCov">         89 :   lua_setfield(L, -2, &quot;charpattern&quot;);</span>
<span class="lineNum">     287 </span><span class="lineCov">         89 :   return 1;</span>
<span class="lineNum">     288 </span>            : }
<span class="lineNum">     289 </span>            : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
